package com.kidala.codility;

public class Equi {

    public static void main(String[] args) {
        Equi equi = new Equi();
        int[] A = new int[] { -7, 1, 5, 2, -4, 3, 0 };
        int result = equi.equi(A);
        System.out.println(result);
    }

    int equi(int[] A) {
        int length = A.length;
        long sum = 0;
        for (int k = 0; k < length; k++) {
            sum += A[k];
        }

        long sumBefore = 0;
        long sumAfter = 0;
        for (int z = 0; z < length; z++) {
            long current = A[z];
            sumAfter = sum - sumBefore - current;

            if (sumBefore == sumAfter) {
                return z;
            }
            sumBefore += current;
        }
        return -1;
    }
}
